import 'package:flutter/material.dart';

class CustomTitle extends StatelessWidget {
  // 调用时会传入用户名、id、透明度、滚动百分比、头像图片路径等参数

  const CustomTitle({
    super.key,
    this.title = '个人中心',
    this.userName = 'userName',
    this.userId = 'userId',
    this.alpha = 0,
    this.scrollProgress = 0,
    this.avatarPath = '',
  });

  final String title;
  final String userName;
  final String userId;
  final int alpha;
  final double scrollProgress;
  final String avatarPath;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Opacity(
          opacity: scrollProgress,
          child: Row(
            children: [
              CircleAvatar(
                backgroundImage: AssetImage(avatarPath),
                radius: 20,
              ),
              const SizedBox(width: 10),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    userName,
                    style: const TextStyle(
                      color: Colors.black,
                      fontSize: 16,
                    ),
                  ),
                  const SizedBox(height: 4),
                  Text(
                    'ID: $userId',
                    style: const TextStyle(color: Colors.black, fontSize: 12),
                  ),
                ],
              )
            ],
          ),
        ),
        Opacity(
          opacity: 1 - scrollProgress,
          child: Container(
            alignment: Alignment.center,
            child: Text(
              title,
              style: const TextStyle(
                color: Colors.white,
              ),
            ),
          ),
        ),
      ],
    );
  }
}
